﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FormatTest
{
    public class ColumbusDecode
    {


        public static int Columbus_ue(string bytes, ref int index)
        {
            int leadingZeroBits = -1;
            for (var b = 0; b == 0; leadingZeroBits++)
            {
                b = Convert.ToInt32(bytes.Substring(index, 1));
                index++;
            }
            return Convert.ToInt32(Math.Pow(2, leadingZeroBits) - 1 + Convert.ToInt32(Common.TwoToTen(Common.read_bits(bytes, leadingZeroBits, ref index))));
        }


        public static int Columbus_se(string bytes, ref int index)
        {
            var i = Columbus_ue(bytes, ref index);
            return Convert.ToInt32(Math.Pow(-1, i + 1) * Math.Ceiling(Convert.ToDouble(i / 2)));
        }
    }
}
